package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mail.dubbo.mapper.SmsCouponProductCategoryRelationMapper;
import com.mail.model.db.SmsCouponProductCategoryRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author yan
 * @date 2022/06/22 21:06
 **/
@DubboService
public class SmsCouponProductCategoryRelationApiImpl implements SmsCouponProductCategoryRelationApi {
    @Autowired
    private SmsCouponProductCategoryRelationMapper mapper;

    @Override
    public void add(SmsCouponProductCategoryRelation smsCouponProductCategoryRelation) {
        mapper.insert(smsCouponProductCategoryRelation);
    }

    @Override
    public void delete(Long id) {
        mapper.deleteByCouponId(id);
    }

    @Override
    public void update(SmsCouponProductCategoryRelation smsCouponProductCategoryRelation, Long id) {
        LambdaQueryWrapper<SmsCouponProductCategoryRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SmsCouponProductCategoryRelation::getCouponId, id);
        mapper.update(smsCouponProductCategoryRelation, wrapper);
    }

    @Override
    public SmsCouponProductCategoryRelation getCouponById(Long id) {
        LambdaQueryWrapper<SmsCouponProductCategoryRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SmsCouponProductCategoryRelation::getCouponId, id);
        return mapper.selectOne(wrapper);
    }
}
